from google.appengine.ext.webapp import template
import os
class Template(object):
    
    debug = True
    scripts =[]
    styles = []
    values = {'title':'default title','rootPath':'/'}
    
    def __init__(self, *args, **kwargs):
        self.values = dict((Template.values or {}).items() + (kwargs.get('values',None) or {}).items())
        self.path = kwargs['path'] or 'static/templates/feed.template'
        self.scripts = kwargs.get('scripts',[])+Template.scripts
        self.styles = kwargs.get('styles',[])+Template.styles
    
    @property
    def includes(self):
        s = ''
        if Template.debug:
            for style in self.styles:
                s+='<link type="text/css" rel="stylesheet" href="'+style+'">\n'
                
                
            for script in self.scripts:
                s+='<script type="text/javascript" src="'+script+'"></script>\n'
        return s
    
    
    
    def render(self, handler):
        path = os.path.join(os.path.dirname(__file__),'..', self.path)
        
        template_values = {'template':self,'values':self.values,'handler':handler}
        handler.response.out.write(template.render(path, template_values))
        